﻿namespace DataAccess
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class OrienteeringMapsDataAccess
    {
        private readonly OrienteeringMapsEntities orienteeringMapsEntities = new OrienteeringMapsEntities();

        public void AddMap(Map map)
        {
            this.orienteeringMapsEntities.AddToMaps(map);
            this.orienteeringMapsEntities.SaveChanges();
        }

        public void DeleteMap(Map map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map", "Map cannot be null to be added to database.");
            }
 
            this.orienteeringMapsEntities.DeleteObject(map);
            this.orienteeringMapsEntities.SaveChanges();
        }

        public void DeleteAllMaps()
        {
            foreach (Map map in this.GetMaps())
            {
                this.orienteeringMapsEntities.DeleteObject(map);
                this.orienteeringMapsEntities.SaveChanges();
            }
        }

        public List<Map> GetMaps()
        {
            return this.orienteeringMapsEntities.Maps.ToList();
        }

        public void AddScale(MapScale scale)
        {
            this.orienteeringMapsEntities.AddToMapScales(scale);
            this.orienteeringMapsEntities.SaveChanges();
        }

        public void DeleteAllScales()
        {
            foreach (MapScale scale in this.GetScales())
            {
                this.orienteeringMapsEntities.DeleteObject(scale);
            }

            this.orienteeringMapsEntities.SaveChanges();
        }

        public List<MapScale> GetScales()
        {
            return this.orienteeringMapsEntities.MapScales.ToList();
        }

        public void AddClub(Club club)
        {
            this.orienteeringMapsEntities.AddToClubs(club);
            this.orienteeringMapsEntities.SaveChanges();
        }

        public void DeleteAllClubs()
        {
            foreach (Club club in this.GetClubs())
            {
                this.orienteeringMapsEntities.DeleteObject(club);
            }

            this.orienteeringMapsEntities.SaveChanges();
        }

        public List<Club> GetClubs()
        {
            return this.orienteeringMapsEntities.Clubs.ToList();
        }

        public void AddPointOfSale(PointOfSale pointOfSale)
        {
            this.orienteeringMapsEntities.AddToPointsOfSale(pointOfSale);
            this.orienteeringMapsEntities.SaveChanges();
        }

        public void DeleteAllPointsOfSale()
        {
            foreach (PointOfSale pointOfSale in this.GetPointsOfSale())
            {
                this.orienteeringMapsEntities.DeleteObject(pointOfSale);
            }

            this.orienteeringMapsEntities.SaveChanges();
        }

        public List<PointOfSale> GetPointsOfSale()
        {
            return this.orienteeringMapsEntities.PointsOfSale.ToList();
        }
    }
}
